/**
 * @Desc 所有的 家辅 Api
 */

import axios from './request';

// 获取特定模块学习记录接口 catId 课程id
export async function getRecordsByModule ({ catId, module }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/module_records/get_records_by_module/`, {
    params: { catId, module }
  });
  return data;
}

// 添加模块下的资源学习记录信息
export async function addRecord ({ catId, resId, resType, module, duration, purpose }) {
  const { data } = await axios.post(`${process.env.VUE_APP_NRMS_URL}/rms/v1/module_records/add_record`, {
    purpose,
    catId,
    resId,
    resType,
    module,
    duration
  });
  return data;
}

// 根据目录编码获取同步培优模块信息
export async function getModulesByCatid ({ catId }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/modules/get_modules_by_catid`, {
    params: { catId }
  });
  return data;
}

// 获取特定目录下所有模块学习记录接口
export async function getRecords ({ catId, resType, resIds }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/module_records/get_records`, {
    params: { catId, resType, resIds }
  });
  return data;
}
/*
 *@functionName: getTemplateNextItems
 *@params1:tagIdEnumCodes
 *@params2: templateId
 *@params3: isFetchItemMedia
 *@description:根据模板编码以及模板树节点的前几级节点编码，获取子节点元素列表
 *@author: wudandan
 *@date: 2021-01-21 13:34:02
*/
export async function getTemplateNextItems ({ tagIdEnumCodes, templateId, isFetchItemMedia }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/tags/get_template_next_items`, {
    params: { tagIdEnumCodes, templateId, isFetchItemMedia }
  });
  return data;
}
/*
 *@functionName: getTagBookCat
 *@params1: nodeId
 *@params2: section
 *@params3: grade
 *@params4: subject
 *@description:获取辅学的特定学科可选择的教材和默认的章节
 *@author: wudandan
 *@date: 2021-01-21 15:18:55
*/
export async function getTagBookCat ({ nodeId, section, grade, subject }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/modules/get_tag_level_book_cat`, {
    params: { nodeId, section, grade, subject }
  });
  return data;
}

/*
 *@functionName: addBookRecord
 *@params1: catId
 *@params2: resId
 *@params3: resType
 *@params4: purpose
 *@params5: duration
 *@description:设置版本下目录的进度  catId=bookid,resId=目录编码，resType=资源类型5，目录类型
 *@author: wudandan
 *@date: 2021-01-25 11:20:48
*/
export async function addBookRecord ({ catId, resId, resType, purpose, duration }) {
  const { data } = await axios.post(`${process.env.VUE_APP_NRMS_URL}/rms/v1/cat_records/add_record`, {
    catId,
    resId,
    resType,
    purpose,
    duration
  });
  return data;
}

/*
 *@functionName: getBookCatalog
 *@params1: bookId
 *@description:获取特定用户在特定目录下的浏览记录
 *@author: wudandan
 *@date: 2021-01-21 15:18:55
*/
export async function getBookCatalog ({ bookId }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/cat_records/get_book_progress`, {
    params: { bookId }
  });
  return data;
}

/*
 *@functionName: getSpecialCrouseTree
 *@params1: bookId
 *@params2: isNew   是否标记new  0-是 ，1-否
 *@description:根据专项课程编码获取专项目录接口
 *@author: wudandan
 *@date: 2021-03-09 09:02:16
 */
export async function getSpecialCrouseTree ({ bookId, isNew }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_special_course`, {
    params: {
      bookId,
      isNew
    }
  });
  return data;
}

/**
 * 根据标签获取资源列表（分页）
 */

export async function getPageResourceListByTag ({
  sourceCode,
  startTime,
  endTime,
  queryType,
  section,
  subject,
  posterType,
  pageNum,
  pageSize,
  tagList
}) {
  const { data } = await axios.post(
    `${process.env.VUE_APP_NRMS_URL}/rms/v1/teachpackage/get_page_resource_list_by_tag`,
    { sourceCode, startTime, endTime, queryType, section, subject, posterType, pageNum, pageSize, tagList }
  );
  return data;
}
